package me.linkcn.ydtxl.server.resources;

import me.linkcn.ydtxl.server.objects.Account;
import me.linkcn.ydtxl.server.objects.ObjectsFacade;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Put;

/**
 * Created by IntelliJ IDEA.
 * User: cmcc
 * Date: 11-8-15
 * Time: 上午12:37
 */
public class AccountResource extends BaseResource {
    @Put
    public Representation login(Representation input) {
        allowOtherHost();
        System.out.println(input.getMediaType());
        JacksonRepresentation<Account> accountRep = new JacksonRepresentation<Account>(input, Account.class);
        Account account = accountRep.getObject();
        System.out.println("gid:" + account.getGid());
        System.out.println("accountType:" + account.getAccountType());
        System.out.println("accountName:" + account.getAccountName());
        System.out.println("password:" + account.getPassword());
        System.out.println(getRequest().getResourceRef());
        ObjectsFacade dataFacade = getObjectsFacade();
        account = dataFacade.getAccountByLoginPwd(account.getAccountName(), account.getPassword().toCharArray());
        if (account != null) {
            return new JacksonRepresentation<Account>(account);
            //return new StringRepresentation(account.getAccountName());
        } else {
            return null;
            //return new StringRepresentation("用户名或密码错误！");
        }
    }
}
